﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ViewMaker.Core.Tests;
using System.Diagnostics;

namespace ViewMaker.SampleApplication
{
    /// <summary>
    /// MainWindow.xaml の相互作用ロジック
    /// </summary>
    public partial class MainWindow : Window
    {
        private List<WeakReference> viewList = new List<WeakReference>();
        private List<WeakReference> viewModelList = new List<WeakReference>();


        public MainWindow()
        {
            InitializeComponent();
        }

        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            var vm = new TestViewModel();
            var view = ViewUtil.BuildContent(vm);
            this.main.Content = view;
            viewList.Add(new WeakReference(view));
            viewModelList.Add(new WeakReference(vm));

        }
        private void MenuItem_Click2(object sender, RoutedEventArgs e)
        {
            var vm = new SampleViewModel();
            this.main.Content = ViewUtil.BuildContent(vm);
        }

        private void MenuItem_Online(object sender, RoutedEventArgs e)
        {
            this.main.Content = ViewUtil.BuildContent(new OnlineViewMaker());
        }

        private void ClearClick(object sender, RoutedEventArgs e)
        {
            this.main.Content = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
            Debug.WriteLine("Active View:" + viewList.Count(x => x.IsAlive));
            Debug.WriteLine("Active ViewModel:" + viewModelList.Count(x => x.IsAlive));
            Debug.WriteLine("TotalMemory:" + GC.GetTotalMemory(true).ToString());

        }
        
    }
}
